package com.xm.queue.task;

/**
 * 测试并发限流控制是否生效
 */
public class TestTask2 {
    public static void main(String[] args) {
        System.out.println("核心线程数：" + Runtime.getRuntime().availableProcessors());

        Thread threadPut = new Thread(() -> {
            Producer.testLimiterPut(100);
        });
        Thread threadPut2 = new Thread(() -> {
            Producer.testLimiterPut(100);
        });
        Thread threadPoll = new Thread(() -> {
            Producer.testLimiterPoll(100);
        });
        try {
            threadPut.start();
            threadPoll.start();

            threadPut.join();
            System.out.println("-------------------------");
            Thread.sleep(1000L);
            threadPut2.start();
            threadPut2.join();
            System.out.println("-------------------------");
            threadPoll.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

//        Producer.testLimiterPut(100);
//        System.out.println("-------------------------");
//        Producer.testLimiterPoll(100);

        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("size = " + TaskUtil.QUEUE.size());
        System.out.println("count = " + TaskUtil.count());
        System.out.println("realPutCount = " + TaskUtil.realPutCount.intValue());
        System.out.println("realPollCount = " + TaskUtil.realPollCount.intValue());
    }
}
